%%%-------------------------------------------------------------------
%%% @author Rain
%%% @doc 帧同步相关处理器
%%% @end
%%%-------------------------------------------------------------------
-module(lock_step_phandler).
-author("Rain").
-include("common.hrl").
-include("lock_step_pb.hrl").
-include("role.hrl").
-include("lock_step_cb.hrl").
-include_lib("elock_step/include/ls_room_svr.hrl").

%% API
-export([handle_c2s_msg/2]).

%% @doc 处理c2s消息
handle_c2s_msg(#lock_step_frame_message_c2s{frame = CliFrame, input = PInput},
    #role_state{role_id = RoleId} = RoleState) ->
    #p_ls_input{parameters = #p_ls_input_param{button = Button}} = PInput,
    LsInput = #ls_input{button = Button},
    ls_room_svr_util:client_call_frame_message(RoleId, CliFrame, LsInput),
    {noreply, RoleState};

handle_c2s_msg(#lock_step_match_c2s{}, #role_state{role_id = RoleId} = RoleState) ->
    PoolName = lock_step_cb:match_pool_name(?LS_MATCH_TYPE_1V1),
    MatchFun =
        fun(MatchSvr) ->
            ls_match_svr_util:client_call_match(RoleId, MatchSvr)
        end,
    poolboy:transaction(PoolName, MatchFun),
    {noreply, RoleState};

handle_c2s_msg(#lock_step_change_scene_finish_c2s{}, #role_state{role_id = RoleId} = RoleState) ->
    ls_room_svr_util:client_call_change_scene_finish(RoleId),
    {noreply, RoleState};


handle_c2s_msg(#lock_step_check_hash_c2s{}, RoleState) ->

    {noreply, RoleState};

handle_c2s_msg(#lock_step_reconnect_c2s{}, RoleState) ->

    {noreply, RoleState};

handle_c2s_msg(Msg, #role_state{} = RoleState) ->
    ?LOG_ERROR("unhandler c2s msg  ~p", [Msg]),
    {noreply, RoleState}.
